package com.epta.service;

import com.epta.pojo.FriendLink;
import com.epta.common.util.DateTimeUtil;
import com.epta.vo.FriendLinkBackListVo;
import com.github.pagehelper.PageInfo;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Administrator on 2017/6/20 0020.
 */
@Service
public class FriendLinkService extends BaseService<FriendLink> {

    public PageInfo<FriendLinkBackListVo> queryListForBack(int page, int rows){
        PageInfo pageInfo = this.queryPageListByWhere(null,page,rows);
        List<FriendLinkBackListVo> list = new ArrayList<>();
        for(Object o : pageInfo.getList()){
            FriendLink friendLink = (FriendLink)o;
            FriendLinkBackListVo friendLinkBackListVo = assembleFriendLinkBackListVo(friendLink);
            list.add(friendLinkBackListVo);
        }
        pageInfo.setList(list);
        return pageInfo;
    }
    private FriendLinkBackListVo assembleFriendLinkBackListVo(FriendLink friendLink){
        FriendLinkBackListVo friendLinkBackListVo = new FriendLinkBackListVo();
        friendLinkBackListVo.setId(friendLink.getId());
        friendLinkBackListVo.setTime(DateTimeUtil.dateToStr(friendLink.getCreated()));
        friendLinkBackListVo.setName(friendLink.getName());
        friendLinkBackListVo.setUrl(friendLink.getUrl());

        return friendLinkBackListVo;
    }
}
